<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     *	- or -
     * 		http://example.com/index.php/welcome/index
     *	- or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */

    public function setting_pagination($cat = 'PL005'){
        $config['base_url'] = base_url() . 'index.php/welcome/page/' . $cat;
        $config['total_rows'] = $this->cart_model->total_product_category($cat);
        error_log(print_r($this->cart_model->total_product_category($cat), TRUE));
        $config['per_page'] = 12;

        $config['full_tag_open'] = '<div class="pagination pagination-centered">  <ul>';
        $config['full_tag_close'] = '</ul></div>';

        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';

        $config['cur_tag_open'] = "<li class='active'><a class='pagination-item' role='button' href='#'>";
        $config['cur_tag_close'] = '</a></li>';

        $config['first_link'] = 'Đầu tiên';
        $config['last_link'] = 'Cuối cùng';

        $config['next_link'] = 'Tiếp »';
        $config['prev_link'] = 'Lùi «';

        $config['first_tag_open'] = '<li>';
        $config['first_tag_close'] = '</li>';

        $config['last_tag_open'] = '<li>';
        $config['last_tag_close'] = '</li>';

        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';

        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';

        $config['num_links'] = 3;
        $config['anchor_class'] = 'class="pagination-item"';


        $this->pagination->initialize($config);
    }

    public function __construct(){
        parent::__construct();
    }

    public function index()
    {

    }

    public function switch_lang($lang = 'vi'){
        switch($lang){
            case 'vi':
                $this->session->set_userdata('language', 'vietnamese');
                break;
            case 'en':
                $this->session->set_userdata('language', 'english');
                break;
        }
        redirect('welcome/page');
    }

    public function page($cat = 'PL005', $page = 0){
        if (!$this->session->userdata('language')){
            $this->session->set_userdata('language', 'vietnamese');
        }
        $data['products1'] = $this->cart_model->retrieve_products(4, $page, $cat);
        $data['products2'] = $this->cart_model->retrieve_products(4, $page + 4, $cat);
        $data['products3'] = $this->cart_model->retrieve_products(4, $page + 8, $cat);

        $this->setting_pagination($cat);

        $this->lang->load('frontpage', $language = $this->session->userdata('language'));
        $this->load->view('welcome_message', $data);
    }

    public function get_new_product_list($page = 0){
        $data['products1'] = $this->cart_model->retrieve_products(4, $page);
        $data['products2'] = $this->cart_model->retrieve_products(4, $page + 4);
        $data['products3'] = $this->cart_model->retrieve_products(4, $page + 8);
        $data['content'] = 'cart/products';

        $this->load->view('cart/products', $data);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */


